package com.egoo.ticket.server.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.egoo.ticket.server.dao.*;
import com.egoo.ticket.server.pojo.dto.SysOptLogDto;
import com.egoo.ticket.server.pojo.dto.SystemMsgDto;
import com.egoo.ticket.server.pojo.entity.*;
import com.egoo.ticket.server.pojo.vo.EwsDepartmentVo;
import com.egoo.ticket.server.project.ProjectConstant;
import com.egoo.ticket.server.service.EripDataSynService;
import com.egoo.ticket.server.service.RoleService;
import com.egoo.ticket.server.service.UserService;
import com.egoo.ticket.server.service.WorkOrderLogService;
import com.egoo.ticket.server.utils.common.*;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author：victor_tang
 * @Date ：2020/2/26
 * @Description：ERIP数据同步实现类
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class EripDataSynRestServiceImpl implements EripDataSynService {
	@Autowired
	private RoleService roleService;
	@Autowired
	private UserService userService;
	@Autowired
	private EwsUserDao ewsUserDao;
	@Autowired
	private CommonUtil commonUtil;
	@Autowired
	private EwsDepartmentDao ewsDepartmentDao;
	@Autowired
	private TreeDataHandleUtil treeDataHandleUtil;
	@Autowired
	private WorkOrderLogService workOrderLogService;
	@Autowired
	private RestTemplate restTemplate;

	@Resource(name = "normalRestTemplate")
	private  RestTemplate normalRestTemplate;

	//erip适配器请求路径
	@Value("${server.erip-adapter-url}")
	private String eripAdapterUrl;

	@Value("${server.dbsrv-url}")
	private String dbsrvUrl;
	@Value("${server.business-server-url}")
	private String businessServerUrl;
	@Value("${server.project-sign}")
	private String projectSign;
	@Value("${server.eurm-server-url}")
	private String eurmUrl;
	@Autowired
	private MsgUtil msgUtil;
	@Autowired
	private MsgTemplateMapper msgTemplateMapper;
	@Autowired
	private WorkOrderDao workOrderDao;
	@Autowired
	private WorkOrderRelationMapper workOrderRelationMapper;

	SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	/**
	 * TODO 同步用户及用户角色权限信息
	 *
	 * @param user 1
	 * @author: victor_tang
	 * @createtime: 2020/2/26 11:58
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse userDataSyn(String user) {
		log.info(user);
		try {
			// 主动调取ERIP接口获取角色数据,后期改MQ
			String allUserStr = getAllUser();
			if (StringUtils.isEmpty(allUserStr)) {
				log.info("获取用户信息为空");
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取用户信息为空");
			}

			// 解析数据
			JSONArray dataList = JSONObject.parseObject(allUserStr).getJSONObject("info").getJSONArray("data");

			// 根据userName过滤重复用户数据
			dataList = filterRepeatData(dataList);

			// 组装用户数据
			List<EwsUser> ewsUserList = handleUserInfo(dataList);

			List<EwsUserRole> ewsUserRoleList = handleUserRoleRelation(dataList);

			// 批量新增
			if (ewsUserList != null && ewsUserList.size() > 0 && ewsUserRoleList != null
					&& ewsUserRoleList.size() > 0) {
				userService.addUserBatch(ewsUserList, ewsUserRoleList);
				log.info("系统用户及用户角色关系同步成功！");

			}
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, "系统用户及用户角色关系同步成功！");
		} catch (Exception e) {

			log.info("系统用户及用户角色关系同步异常：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "系统用户及用户角色关系同步异常：" + e);
		}
	}

	/**
	 * TODO 根据userName过滤重复用户数据
	 *
	 * @param dataList 1
	 * @author: victor_tang
	 * @createtime: 2020/2/24 12:22
	 * @return: com.alibaba.fastjson.JSONArray
	 */
	private JSONArray filterRepeatData(JSONArray dataList) {
		if (dataList == null || dataList.isEmpty()) {
			return null;
		}
		JSONArray returnData = new JSONArray();
		Set<String> userNameSets = new HashSet<>();
		for (int i = 0; i < dataList.size(); i++) {
			JSONObject jsonObject1 = dataList.getJSONObject(i);
			String userName = jsonObject1.getString("userName");
			if (StringUtils.isEmpty(userName)) {
				continue;
			}
			if (userNameSets.contains(userName.toLowerCase())) {
				continue;
			}
			userNameSets.add(userName.toLowerCase());
			returnData.add(jsonObject1);
		}
		return returnData;
	}

	/**
	 * TODO 同步角色信息
	 *
	 * @param role 1
	 * @author: victor_tang
	 * @createtime: 2020/2/26 11:58
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse roleDataSyn(String role) {
		log.info(role);
		try {
			// 主动调取ERIP接口获取角色数据,后期改MQ
			String allRoleStr = getAllRole();
			if (StringUtils.isEmpty(allRoleStr)) {
				log.info("获取角色信息为空");
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取角色信息为空!");
			}

			List<EwsRole> ewsRoleList = new ArrayList<EwsRole>();
			// 解析数据
			JSONArray dataList = JSONObject.parseObject(allRoleStr).getJSONObject("info").getJSONArray("data");

			for (int i = 0; i < dataList.size(); i++) {
				EwsRole ewsRole = new EwsRole();
				String id = dataList.getJSONObject(i).getString("uuid");
				ewsRole.setId(id);

				String roleCode = dataList.getJSONObject(i).getString("code");
				ewsRole.setCode(roleCode);

				String roleName = dataList.getJSONObject(i).getString("name");
				ewsRole.setName(roleName);

				String tenantId = dataList.getJSONObject(i).getString("orgCode");
				if (StringUtils.isEmpty(tenantId)) {
					continue;
				}
				ewsRole.setTenantId(tenantId);

				ewsRoleList.add(ewsRole);
			}

			// 批量新增
			if (ewsRoleList.size() > 0) {
				roleService.addRoleBatch(ewsRoleList);
				log.info("系统角色同步成功！");
			}
//			// 角色或者部门同步成功后同步，工单当前处理人信息
//			hisWorkOrderCurrentHandlePersonSyn();
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, "系统角色同步成功！");
		} catch (Exception e) {

			log.info("系统角色信息同步异常" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "系统角色信息同步异常" + e);
		}

	}
	/**
	 * TODO 同步部门信息
	 * @author: victor_tang
	 * @createtime: 2020/3/17 12:18
	 * @param dept 1
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse deptDataSyn(String dept) {
		log.info(dept);
		// ERIP适配器地址
//		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		String csrUrl = eurmUrl + "/if/data/transfer/list.ptc";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Type", "application/json");
//			headers.add("erip-action", "query");
//			headers.add("erip-source", "ERIP");
//			headers.add("erip-target", "Tree");
			// 设置body参数
//			Map body = new HashMap();
//			body.put("treeName","Dept");
//			body.put("treeTargetNodeName","0");
//			String jsonData = JSON.toJSONString(body);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("systemCode","");
			jsonObject.put("dataType","Dept");
			String jsonData = jsonObject.toString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("ERIP获取部门信息列表数据===》" + result);
			if (StringUtils.isEmpty(result)) {
				log.info("获取部门信息为空！");
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取部门信息为空");
			}
			// 解析数据
			JSONArray dataList = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");
			if (dataList==null || dataList.size()==0) {
				log.info("获取部门信息为空！");
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取部门信息为空");
			}
			// 处理部门信息
			List<EwsDepartment> ewsDepartments = handleDeptInfo(dataList);

			if (!CollectionUtils.isEmpty(ewsDepartments)) {
				String tenantId = ewsDepartments.get(0).getTenantId();
				ewsDepartments.stream().map(ewsDepartment -> ewsDepartment.setTenantId(tenantId)).collect(Collectors.toList());
				// 删除部门所有信息
				int delete = ewsDepartmentDao.deleteAllDept(tenantId);
				log.info("删除部门所有信息结果:"+delete);
				// 同步部门数据至数据库
				ewsDepartmentDao.insertBatch(ewsDepartments);
			}

//			// 角色或者部门同步成功后同步，工单当前处理人信息
//			hisWorkOrderCurrentHandlePersonSyn();

			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, "部门信息同步成功！");
		} catch (Exception e) {
			log.error("获取部门信息异常信息：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取部门信息异常：" + e);
		}
	}
	/**
	 * TODO 处理部门信息数据
	 * @author: victor_tang
	 * @createtime: 2020/3/17 12:31
	 * @param dataList 1
	 * @return: java.util.List
	 */
	private List handleDeptInfo(JSONArray dataList){
		List<EwsDepartment> ewsDepartments = new ArrayList<>();
		for (int i = 0; i < dataList.size(); i++) {
			EwsDepartment ewsDepartment = new EwsDepartment();
			JSONObject jsonObject = dataList.getJSONObject(i);
			ewsDepartment.setId(jsonObject.getString("code"));
			ewsDepartment.setName(jsonObject.getString("name"));
			ewsDepartment.setPid(jsonObject.getString("parent"));
			String tenantId =jsonObject.getString("orgCode");
			if (StringUtils.isEmpty(tenantId)) {
				continue;
			}
				ewsDepartment.setTenantId(tenantId);

			ewsDepartments.add(ewsDepartment);
		}
		return ewsDepartments;
	}

	/**
	 * TODO 获取用户权限列表
	 *
	 * @param tenantId 1
	 * @param userId   2
	 * @author: victor_tang
	 * @createtime: 2020/3/10 18:22
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse getUserPermissionsList(String tenantId, String userId) {
		// ERIP适配器地址
		String csrUrl = eripAdapterUrl + "/csr/adapter/v1/query/user/info" +
				"?tenantId=" + tenantId + "&userCode=" + userId + "";
		try {
			String result = restTemplate.getForObject(csrUrl, String.class);
//			log.info("获取用户权限列表getUserPermissionsList==》" + result);
			// 解析数据
			JSONObject jsonObject = JSONObject.parseObject(result).getJSONObject("data");
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, ResponseConstant.SELECT_SUCCESS_MSG, jsonObject);

		} catch (Exception e) {
			log.error("获取用户权限列表请求响应异常信息：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取用户权限列表请求响应异常信息：" + e);
		}
	}

	/**
	 * TODO 处理用户信息
	 *
	 * @param dataList 1
	 * @author: victor_tang
	 * @createtime: 2020/2/26 11:59
	 * @return: java.util.List<com.egoo.ticket.server.vo.EwsUser>
	 */
	private List<EwsUser> handleUserInfo(JSONArray dataList) {
		List<EwsUser> ewsUserList = new ArrayList<EwsUser>();
		for (int i = 0; i < dataList.size(); i++) {
			// 组装用户信息
			EwsUser ewsUser = new EwsUser();
			JSONObject jsonObject = dataList.getJSONObject(i);
			String id = jsonObject.getString("userName");
			ewsUser.setId(id);

			String roleCode = jsonObject.getString("code");
			ewsUser.setCode(roleCode);

			String roleName = jsonObject.getString("name");
			ewsUser.setName(roleName);

			String userName = jsonObject.getString("userName");
			ewsUser.setUserName(userName);

			String phone = jsonObject.getString("phone");
			ewsUser.setPhone(phone);
			String email = jsonObject.getString("email");
			ewsUser.setEmail(email);
			String deptId = jsonObject.getString("dept");
			ewsUser.setDepartmentId(deptId);
			String isLeader = jsonObject.getString("responsible");
			ewsUser.setIsLeader(isLeader);
			String tenantId = jsonObject.getString("orgCode");

			if (StringUtils.isEmpty(tenantId)) {
				continue;
			}
			ewsUser.setTenantId(tenantId);

			ewsUserList.add(ewsUser);
		}

		return ewsUserList;
	}

	/**
	 * TODO 获取系统所有角色信息
	 *
	 * @param
	 * @author: victor_tang
	 * @createtime: 2020/2/26 12:00
	 * @return: java.lang.String
	 */
	@Override
//	@Retryable(value = {SocketTimeoutException.class},maxAttempts= 3,backoff = @Backoff(value = 1000L))
	public String getAllRole() {
		// ERIP适配器地址
//		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		String csrUrl = eurmUrl + "/if/data/transfer/list.ptc";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
//			headers.add("erip-action", "query");
//			headers.add("erip-source", "ticket");
//			headers.add("erip-target", "Role");
			headers.add("Content-Type", "application/json");
			// 设置body参数
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("systemCode","");
			jsonObject.put("dataType","Role");
			String jsonData = jsonObject.toString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("ERIP获取角色列表getAllRole==》" + result);
			return result;

		} catch (Exception e) {
			log.info("post请求响应异常信息：" + e);
			return "";
		}
	}

	/**
	 * TODO 处理用户角色关系信息
	 *
	 * @param dataList 1
	 * @author: victor_tang
	 * @createtime: 2020/2/26 11:59
	 * @return: java.util.List<com.egoo.ticket.server.vo.EwsUserRole>
	 */
	private List<EwsUserRole> handleUserRoleRelation(JSONArray dataList) {
		List<EwsUserRole> ewsUserRoleList = new ArrayList<EwsUserRole>();
		for (int i = 0; i < dataList.size(); i++) {
			JSONArray roleList = dataList.getJSONObject(i).getJSONArray("roles");
			for (int j = 0; j < roleList.size(); j++) {
				// 组装用户信息
				EwsUserRole ewsUserRole = new EwsUserRole();

				JSONObject userObj = dataList.getJSONObject(i);
				if (!userObj.isEmpty()) {
					ewsUserRole.setUserId(userObj.getString("userName"));
				}

				JSONObject roleObj = roleList.getJSONObject(j);
				if (!roleObj.isEmpty()) {
					ewsUserRole.setRoleId(roleObj.getString("uuid"));
				}

				if (ewsUserRole.getRoleId() != null && ewsUserRole.getUserId() != null) {
					ewsUserRoleList.add(ewsUserRole);
				}

			}

		}
		return ewsUserRoleList;
	}

	/**
	 * TODO 获取系统所有用户信息
	 *
	 * @param
	 * @author: victor_tang
	 * @createtime: 2020/2/26 12:00
	 * @return: java.lang.String
	 */
	@Override
//	@Retryable(value = {SocketTimeoutException.class, ResourceAccessException.class}, backoff = @Backoff())
	public String getAllUser() {
		// ERIP适配器地址
//		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		String csrUrl = eurmUrl + "/if/data/transfer/list.ptc";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
//			headers.add("erip-action", "query");
//			headers.add("erip-source", "ticket");
//			headers.add("erip-target", "UserRole");
			headers.add("Content-Type", "application/json");
			// 设置body参数
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("systemCode","");
			jsonObject.put("dataType","User");
			String jsonData = jsonObject.toString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("ERIP获取用户角色权限数据getAllUser===》" + result);
			return result;
		} catch (Exception e) {
			log.info("post请求响应异常信息：" + e);
			return "";
		}
	}

//	/**
//	 * TODO 获取产品型号信息
//	 * @author: victor_tang
//	 * @createtime: 2020/3/17 11:46
//	 * @param productModelInfoDto 1
//	 * @return: com.egoo.ticket.server.utils.DBResponse
//	 */
//	@Override
//	public DbResponse getProductModelList(ProductModelInfoDto productModelInfoDto) {
//		// ERIP适配器地址
//		String CSR_URL = ERIP_ADAPTER_URL + "/ticket/adapter/v1/query";
//		// 设置请求header参数
//		Map<String, Object> headerMap = new HashMap<String, Object>(8);
//		headerMap.put("Content-Type", "application/json");
//		headerMap.put("erip-action", "query");
//		headerMap.put("erip-source", "ERIP");
//		headerMap.put("erip-target", "Tree");
//		// 设置body参数
//		JSONObject bodyJsonObject = new JSONObject();
//		bodyJsonObject.put("treeName","EWSProductModelInfo");
//		bodyJsonObject.put("treeTargetNodeName","0");
//		JSONObject filterJsonObject=new JSONObject();
//		if (StringUtils.isNotBlank(productModelInfoDto.getModelCode())) {
//			filterJsonObject.put("modelCode", productModelInfoDto.getModelCode());
//		}
//		if (StringUtils.isNotBlank(productModelInfoDto.getCompanyId())) {
//			filterJsonObject.put("companyID", productModelInfoDto.getCompanyId());
//		}
//		if (StringUtils.isNotBlank(productModelInfoDto.getCompanyName())) {
//			filterJsonObject.put("companyName", productModelInfoDto.getCompanyName());
//		}
//		if (StringUtils.isNotBlank(productModelInfoDto.getBelongToClassify())) {
//			filterJsonObject.put("classify", productModelInfoDto.getBelongToClassify());
//		}
//		bodyJsonObject.put("filters",filterJsonObject);
//		try {
//			String bodyStr = bodyJsonObject.toJSONString();
//			// 请求ERIP接口
//			String result = HttpRequestUtil.sendPost(CSR_URL, bodyStr, headerMap);
////			log.info("ERIP获取产品型号信息列表数据getProductModelList===》" + result);
//			// 解析产品型号信息
//			if (StringUtils.isEmpty(result)) {
//				log.info("获取产品型号信息为空！");
//				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取产品型号信息为空");
//			}
//
//			// 解析数据
//			JSONArray dataList = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");
//			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, ResponseConstant.SELECT_SUCCESS_MSG,dataList );
//		} catch (Exception e) {
//			log.info("获取产品型号信息异常信息：" + e);
//			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取产品型号信息异常：" + e);
//		}
//	}
	/**
	 * TODO 获取业务分类信息列表
	 * @author: victor_tang
	 * @createtime: 2020/3/17 12:56
	 * @param
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse getBusinesTypeList() {
		// ERIP适配器地址
		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Type", "application/json");
			headers.add("erip-action", "query");
			headers.add("erip-source", "ERIP");
			headers.add("erip-target", "Tree");
			// 设置body参数
			JSONObject bodyJsonObject = new JSONObject();
			bodyJsonObject.put("treeName","EWSBusinessType");
			bodyJsonObject.put("treeTargetNodeName","0");
			String jsonData = bodyJsonObject.toJSONString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("ERIP获取业务分类数据为："+result);
			// 解析业务分类信息
			if (StringUtils.isEmpty(result)) {
				log.info("获取业务分类信息为空！");
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取业务分类信息为空");
			}
			// 解析数据
			JSONArray dataList = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");

			JSONArray jsondataList = treeDataHandleUtil.transJsonArrayToTreeData(dataList, "parent",
					"busiType", "code", "children");
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,
					ResponseConstant.SELECT_SUCCESS_MSG,jsondataList);
		} catch (Exception e) {
			log.info("获取业务分类信息异常信息：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "获取业务分类信息异常：" + e);
		}
	}

//	/**
//	 * TODO 角色变动后，同步更新历史工单当前处理人
//	 *
//	 * @param
//	 * @author: victor_tang
//	 * @createtime: 2020/2/26 11:59
//	 * @return: com.egoo.ticket.server.utils.DBResponse
//	 */
//	@Override
//	public DbResponse hisWorkOrderCurrentHandlePersonSyn() {
//		// 查询历史当前工单类型节点id列表
//		List<WorkOrder> workOrderList =
//				workOrderDao.selectWorkOrderTypeNodeIds();
//
//		// 根据工单类型节点获取新的节点处理人信息
//		for (WorkOrder workOrder : workOrderList) {
//			Long currentWorkOrderNodeId = workOrder.getCurrentWorkOrderNodeId();
//			if (currentWorkOrderNodeId == null) {
//				continue;
//			}
//			WorkOrderTypeNodeVo workOrderTypeNodeVo = workOrderTypeNodeDao
//					.getNodeByWorkOrderNodeId(currentWorkOrderNodeId);
//			if (workOrderTypeNodeVo == null) {
//				continue;
//			}
//			WorkOrder updateWorkOrder =
//					getworkOrderTypeNodeIdHandlePerson(workOrderTypeNodeVo.getContent(),workOrder.getTenantId());
//			if (updateWorkOrder == null) {
//				continue;
//			}
//			updateWorkOrder.setCurrentWorkOrderNodeId(currentWorkOrderNodeId);
//
//			// 根据当前工单类型节点id，批量更新当前工单处理人信息
//			workOrderDao.updateHandlePersonInfoByNodeId(updateWorkOrder);
//		}
//		log.info("角色变动后，同步更新历史工单当前处理人成功！");
//		return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, "历史工单当前工单处理人更新成功;");
//	}

	/**
	 * TODO 获取工单类型节点新的处理人信息
	 *
	 * @param content 1
	 * @author: victor_tang
	 * @createtime: 2020/2/26 11:59
	 * @return: com.egoo.ticket.server.vo.WorkOrder
	 */
	private WorkOrder getworkOrderTypeNodeIdHandlePerson(JSONObject content,
														 String tenantId) {
		if (content == null) {
			return null;
		}
		String assigneetype = content.getString("assigneetype");
		// 获取节点处理角色列表
		JSONArray assigneeJsonArray = content.getJSONArray("assignee");
		if (assigneeJsonArray == null) {
			return null;
		}
		if (ConstantCode.UserRoleDeptType.USER.equals(assigneetype)) {
			return null;
		}
		// 处理人类型为部门和用户时，需要更新工单当前处理人信息
		if (ConstantCode.UserRoleDeptType.DEPT.equals(assigneetype)
				||ConstantCode.UserRoleDeptType.ROLE.equals(assigneetype)
		) {
			List<String> typeIds = null;
			if (ConstantCode.UserRoleDeptType.DEPT.equals(assigneetype)) {
				typeIds = commonUtil.splitDeptCode(assigneeJsonArray.toJSONString());
			} else {
				typeIds = JSONObject.parseArray(assigneeJsonArray.toJSONString(), String.class);
			}
			// 处理人类型为部门和用户时，需要更新工单当前处理人信息
			List<EwsUser> ewsUsers = userService.getUserListByTypeAndTypeIds(assigneetype, typeIds,
					null);
			List<String> userIdsList = new ArrayList<>();
			List<String> userNamesList = new ArrayList<>();
			for (EwsUser ewsUser : ewsUsers) {
				userIdsList.add(ewsUser.getId());
				userNamesList.add(ewsUser.getName());
			}
			WorkOrder workOrder = new WorkOrder();
			workOrder.setCurrentHandlerId(StringUtils.join(userIdsList,","));
			workOrder.setCurrentHandlerName(StringUtils.join(userNamesList,","));
			return workOrder;
		}
		return null;
	}
	/**
	 * TODO 获取短信模板信息
	 * @author: victor_tang
	 * @createtime: 2020/3/22 16:03
	 * @param
	 * @return: com.alibaba.fastjson.JSONArray
	 */
	@Override
	public JSONArray getTemplate() {
		// ERIP适配器地址
		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Type", "application/json");
			headers.add("erip-action", "query");
			headers.add("erip-source", "ERIP");
			headers.add("erip-target", "Tree");
			// 设置body参数
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("treeName", "MsgFormat");
			jsonObject.put("treeTargetNodeName", 0);
			String jsonData = jsonObject.toJSONString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("erip获取短信模板信息为："+result);
			// 解析数据
			JSONArray dataJsonArray = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");
			if (dataJsonArray == null || dataJsonArray.isEmpty()) {
				return null;
			}
			return dataJsonArray;
		} catch (Exception e) {
			log.info("获取短信模板异常：" + e);
			return null;
		}

	}
	/**
	 * TODO 根据过滤条件和获取短信模板
	 * @author: victor_tang
	 * @createtime: 2020/3/31 17:29
	 * @param filterCondition 1
	 * @return: com.alibaba.fastjson.JSONArray
	 */
	@Override
	public JSONArray getTemplateByFilterCondition(JSONObject filterCondition) {
		// 获取内管配置的短信模板
		JSONArray template = getTemplate();
		if (template==null) {
			return null;
		}
		// 根据短信模板名称进行过滤
		String filterName = filterCondition.getString("name");
		if (StringUtils.isEmpty(filterName)) {
			return template;
		}
		JSONArray templateJsonArray = new JSONArray();
		for (int i = 0; i < template.size(); i++) {
			if (filterName.equals(template.getJSONObject(i).getString("name"))) {
				templateJsonArray.add(template.getJSONObject(i));
			}
		}
		return templateJsonArray;
	}


	/**
	 * TODO 获取短信模板信息(催办)
	 *
	 * @param
	 * @author: victor_tang
	 * @createtime: 2020/2/26 12:24
	 * @return: com.alibaba.fastjson.JSONArray
	 */
	@Override
	public JSONArray getMsgTemplate() {
		// ERIP适配器地址
		String csrUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Type", "application/json");
			headers.add("erip-target", "MsgTemplate");
			headers.add("erip-action","query");
			headers.add("erip-source","ERIP");
			JSONObject jsonObjectBody = new JSONObject();
			jsonObjectBody.put("bussType","工单催办通知");
			String bodyStr = jsonObjectBody.toJSONString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(bodyStr, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			// 解析数据
			JSONArray dataJsonArray = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");
			if (dataJsonArray == null || dataJsonArray.isEmpty()) {
				return null;
			}
			return dataJsonArray;
		} catch (Exception e) {
			log.info("获取短信模板：" + e);
			return null;
		}

	}
	/**
	 * TODO 发送短信
	 * @author: victor_tang
	 * @createtime: 2020/3/18 20:46
	 * @param jsonObject 1
	 * @return: com.egoo.ticket.server.utils.DBResponse
	 */
	@Override
	public DbResponse sendMsg(JSONObject jsonObject) {
		log.info("发送短信开始");
		// ERIP适配器地
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			String csrUrl = null;
			if (ProjectConstant.ProjectSign.JINCHNEG.equals(projectSign)) {
				csrUrl = businessServerUrl + "/business-server/csr/adapter/v1/query";
				headers.add("erip-userid",jsonObject.getString("userId"));
				headers.add("erip-protype","ews-server");
			} else {
				csrUrl = eripAdapterUrl + "/csr/adapter/v1/query";
				headers.add("Content-Type", "application/json");
				headers.add("erip-target","sendSMS");
			}
			log.info("发送短信的header:"+headers);

			// 设置body参数
			JSONObject body = new JSONObject();
			body.put("tranCode","sendMessage");
			JSONObject dataBody = new JSONObject();
			dataBody.put("phone",jsonObject.getString("phoneNumber"));
			dataBody.put("content",jsonObject.getString("content"));
			body.put("data",dataBody);
			String bodyStr = body.toJSONString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(bodyStr, headers);
			//请求接口
			log.info("发送短信的参数:"+body);
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("发送短信响应:" + result);
			// 解析数据
			String code = JSONObject.parseObject(result).getString("code");
//			if (!"000000".equals(code)) {
//				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "发送失败！");
//			}

			// 记录发送短信日志
			recordMsgLog(jsonObject);

			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,"发送成功！");
		} catch (Exception e) {
			log.info("发送异常：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "发送异常：" + e);
		}
	}
	/**
	 * @Author: Donny_dong
	 * @Description: 记录短信log
	 * @Param:
	 * @return:
	 * @Date: 2020/4/10
	 */
	private void recordMsgLog(JSONObject jsonObject) {
		String workOrderId = jsonObject.getString("workOrderId");
		String userId = jsonObject.getString("userId");
		String phoneNumber = jsonObject.getString("phoneNumber");
		String content = jsonObject.getString("content");
		String msgTypeName = jsonObject.getString("msgTypeName");
		String tenantId = jsonObject.getString("tenantId");
		WorkOrderLog workOrderLog = new WorkOrderLog();
		if (StringUtils.isNotBlank(workOrderId)){
			workOrderLog.setWorkOrderId(workOrderId);
		}
		workOrderLog.setLogCreaterId(userId);
		EwsUser ewsUser = ewsUserDao.selectById(userId);
		EwsDepartmentVo ewsDepartmentVo = null;
		if (ewsUser != null) {
			ewsDepartmentVo = ewsDepartmentDao.selectByPrimaryKeyAndTenantId(ewsUser.getDepartmentId(),ewsUser.getTenantId());
			if (ewsDepartmentVo!= null) {
				workOrderLog.setLogCreaterName(ewsUser.getName());
				workOrderLog.setLogCreaterDept(ewsDepartmentVo.getName());
			}
		} else {
			workOrderLog.setLogCreaterName(ConstantCode.SYSTEM_OPERATION_LOGO);
			workOrderLog.setLogCreaterDept(ConstantCode.SYSTEM_OPERATION_LOGO);
		}
		workOrderLog.setLogCreateTime(new Date(System.currentTimeMillis()));
		workOrderLog.setContent(content);
		workOrderLog.setLogType(ConstantCode.WorkOrderLogType.MSG_SEND_CODE);
		workOrderLog.setTenantId(tenantId);
		workOrderLog.setSendAccount(phoneNumber);
		log.info("短信发送日志记录参数：{}"+workOrderLog);
		workOrderLogService.addSave(workOrderLog);
	}
	/**
	 * TODO 发送系统消息
	 * @author: victor_tang
	 * @createtime: 2020/3/22 16:34
	 * @param systemMsgDto 1
	 * @return: java.lang.String
	 */
	@Override
	public DbResponse sendSystemMsg(SystemMsgDto systemMsgDto) {
//		1. title(string): 非必填，消息标题，默认为空
//		2. content(string): 消息内容
//		3. message_type(string): 非必填，消息类型，默认为normal。例：普通消息(normal), 公告(announce)
//		4. target_type(string): 消息发送类型，可选项为：`user`、`group`、`global`，分别为发送给用户的消息，发送给群组的消息和发送给全体的消息。
//		5. targets(array of String): 发送类型为`user`和`group`时可用，标示要接收的群体。
//		6. sender_id(String): 消息发送者ID
		// ERIP适配器地址
//		String csrUrl = eripAdapterUrl + "/messages";
		String csrUrl = eripAdapterUrl + "/message_center/adapter/v1/query";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Type", "application/json");
			headers.add("erip-action", "query");
			headers.add("erip-source", "csr");
			headers.add("erip-target", "PostMessage");
			// 设置body参数
			JSONObject body = new JSONObject();
			body.put("title",systemMsgDto.getTitle());
			body.put("content",systemMsgDto.getContent());
			body.put("message_type","workorder");
			body.put("target_type", "user");
			body.put("targets", systemMsgDto.getTargets());
			body.put("sender_id", systemMsgDto.getSenderId());
			body.put("remark", systemMsgDto.getRemark());
			body.put("tenant_id",systemMsgDto.getTenantId());
			String bodyStr = body.toJSONString();
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(bodyStr, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			log.info("发送系统消息响应:" + result);
			// 解析数据
			Integer code = JSONObject.parseObject(result).getInteger("status");
			if (ResponseConstant.RES_SUCCESS_CODE != code) {
				return new DbResponse(ResponseConstant.RES_FAIL_CODE, "发送失败！");
			}
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,"发送成功！");
		} catch (Exception e) {
			log.info("系统消息发送异常：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE, "发送异常：" + e);
		}
	}

	/**
	 * TODO 获取在线客服工作时间段
	 *
	 * @param
	 * @author: victor_tang
	 * @createtime: 2019/9/27 23:47
	 * @return: java.util.List
	 */
	@Override
	public List<String> getWorkTimeList() {
		// ERIP适配器地址
		String csrUrl = eripAdapterUrl + ":8024/workworder/adapter/v1/resource/query";
		try {
			// 设置header参数
			HttpHeaders headers = new HttpHeaders();
			headers.add("erip-target", "CfgParamItem");
			// 设置body参数
			String bodyStr = "{\r\n" + "   \"Code\": \"ONLINE_BUSINESS\",\r\n" + "   \"filterType\":\"6\"\r\n" + "}";
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(bodyStr, headers);
			//请求接口
			String result = restTemplate.postForObject(csrUrl, request, String.class);
			return handleWorkTimeData(result);
		} catch (Exception e) {
			log.info("获取在线客户工作时间段异常：" + e);
			return null;
		}

	}

	/**
	 * TODO 处理作息工作时间数据
	 *
	 * @param result
	 * @return
	 */
	private List<String> handleWorkTimeData(String result) {
		if (StringUtils.isEmpty(result)) {
			return null;
		}
		JSONArray jsonArray = JSONObject.parseObject(result).getJSONObject("info").getJSONArray("data");
		if (jsonArray == null || jsonArray.isEmpty()) {
			return null;
		}

		List<String> workTimeList = new ArrayList<>();
		for (int i = 0; i < jsonArray.size(); i++) {
			String codeString = jsonArray.getJSONObject(i).getString("code");
			if ("ONLINE_BUSINESS_BEGIN".equals(codeString)) {
				workTimeList.add(jsonArray.getJSONObject(i).getString("value"));
			}
		}
		for (int i = 0; i < jsonArray.size(); i++) {
			String codeString = jsonArray.getJSONObject(i).getString("code");
			if ("ONLINE_BUSINESS_END".equals(codeString)) {
				workTimeList.add(jsonArray.getJSONObject(i).getString("value"));
			}
		}

		return workTimeList;

	}

	/**
	 * TODO 调取工作台记录操作日志接口
	 * @author: victor_tang
	 * @createtime: 2020/5/6 11:49
	 * @param sysOptLogDto 1
	 * @return: com.egoo.ticket.server.utils.common.DbResponse
	 */
	@Override
	public DbResponse recordSysOptLog(SysOptLogDto sysOptLogDto) {
		if (sysOptLogDto==null) {
			log.error("操作日志参数不能为空！");
			return null;
		}
		EwsUser ewsUser = ewsUserDao.selectById(sysOptLogDto.getUserId());
		if (ewsUser!=null) {
			sysOptLogDto.setUserName(ewsUser.getName());
			sysOptLogDto.setAgentId(ewsUser.getId());
		}
		sysOptLogDto.setOptTime(sdfTime.format(new Date()));
		// dbsrv服务地址
		String dbSrvUrl = dbsrvUrl + "/dbsrv/v1/history/operaterecord/";
		try {
			log.info("请求dbsrv日志操作接口参数为："+sysOptLogDto);
			// 设置body参数
			String bodyStr = JSON.toJSONString(sysOptLogDto);
			// 组装请求参数
			HttpEntity<String> request = new HttpEntity<>(bodyStr,null);
			//请求接口
			String result = restTemplate.postForObject(dbSrvUrl, request, String.class);
			log.info("请求工作台系统操作记录接口响应为："+result);
			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE, "操作日志记录成功！");
		} catch (Exception e) {
			log.error("记录系统操作日志至工作台异常：" + e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"记录系统操作日志至工作台异常：" + e);
		}
	}

	@Override
	public JSONObject externalWorkOrderFlowOut(String flowOutUrl,
									  JSONObject jsonObject, JSONObject httpHeader) {
		log.info("获取的转出地址为："+flowOutUrl);
		if (StringUtils.isEmpty(flowOutUrl)){
			log.info("转出的地址不存在:"+flowOutUrl);
		}
		if (Objects.isNull(jsonObject)){
			log.info("转出的参数配置为空"+jsonObject);
		}
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.add("Content-Type","application/json;charset=utf-8");
		if (!Objects.isNull(httpHeader)) {
			httpHeaders.add("erip-target",httpHeader.getString("erip-target"));
			httpHeaders.add("erip-source",httpHeader.getString("erip-source"));
			httpHeaders.add("erip-action",httpHeader.getString("erip-action"));
			httpHeaders.add("Cookie",null);
		} else {
			httpHeaders.add("erip-target","RBPH013");
			httpHeaders.add("erip-source","ticket");
			httpHeaders.add("erip-action","query");
			httpHeaders.add("Cookie",null);
		}
		HttpEntity<Object> httpEntity = new HttpEntity<>(jsonObject,httpHeaders);
		log.info("工单创建转出至ERIP的Adapter参数为："+httpEntity);
		JSONObject resultObj = normalRestTemplate.postForObject(flowOutUrl, httpEntity, JSONObject.class);
		log.info("工单创建转出至ERIP的Adapter相应为："+resultObj);
		return resultObj;
	}

	/**
	 * @Author: Donny_dong
	 * @Description: 获取休息日(此接口已经迁移)
	 * @Param:
	 * @return:
	 * @Date: 2020/8/20
	 */
	@Override
	@Deprecated
	public List<String> getRestDay() {
		String eripUrl = eripAdapterUrl + "ticket/adapter/v1/query";

		JSONObject jsonObject = new JSONObject();
		String bodyStr = jsonObject.toJSONString();
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.add("Content-Type","application/json");
		httpHeaders.add("erip-action","query");
		httpHeaders.add("erip-source","ERIP");
		httpHeaders.add("erip-target","WorkDay");
		HttpEntity<String> httpEntity = new HttpEntity<>(bodyStr, httpHeaders);
		List<String> resultList = null;
		try {
			String result = restTemplate.postForObject(eripUrl, httpEntity, String.class);
			log.info("获取erip的休息日结果为："+result);
			JSONObject jsonResult = JSON.parseObject(result);
			JSONObject info = jsonResult.getJSONObject("info");
			JSONArray dataArray = info.getJSONArray("data");
			resultList = JSON.parseArray(dataArray.toJSONString(), String.class);
		} catch (RestClientException e) {
			e.printStackTrace();
			log.info("获取休息日异常"+e);
		}
		return resultList;
	}

	/**
	 * @Author: Donny_dong
	 * @Description: 发送回访邮件
	 * @Param:
	 * @return:
	 * @Date: 2020/8/20
	 */
	@Override
	public DbResponse sendRevisitEmail(SystemMsgDto<List> systemMsgDto) {
        String emailContent = systemMsgDto.getContent();
        String title = systemMsgDto.getTitle();
		List<String> targets = systemMsgDto.getTargets();
		String workOrderId = systemMsgDto.getId();
		String templateId = systemMsgDto.getTemplateId();
		WorkOrder workOrder = workOrderDao.selectById(workOrderId);
		WorkOrderRelation workOrderRelation = new WorkOrderRelation();
		workOrderRelation.setWorkOrderId(workOrder.getId());
		workOrderRelation  = workOrderRelationMapper.selectWorkOrderRelation(workOrderRelation);
		MsgTemplate msgTemplate = msgTemplateMapper.selectById(templateId);
		title = msgUtil.contentHandle(title,workOrder);
		emailContent = msgUtil.contentHandle(emailContent,workOrder);
		systemMsgDto.setTitle(title);
		systemMsgDto.setSenderId(workOrder.getCustomField().getString("CREATE_AGENTID"));
		systemMsgDto.setSessionId(workOrderRelation.getSessionId());
		systemMsgDto.setContent(emailContent);
		systemMsgDto.setAttachmentAdd(msgTemplate.getAttachmentAddress().toJSONString());
		String result = this.sendEmail(systemMsgDto);
		log.info("返回结果result:"+result);
        log.info("邮件参数:"+"---"+title+"---"+emailContent+"---"+targets);
        if ("200".equals(result)) {
            return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,"邮件回访成功");
        }
        return new DbResponse(ResponseConstant.RES_FAIL_CODE,"邮件回访失败");

	}

	/**
	 * @Author: Donny_dong
	 * @Description: 对接邮件服务器
	 * @Param:
	 * @return:
	 * @Date: 2020/8/21
	 * @param systemMsgDto
	 */
    @Override
    public String sendEmail(SystemMsgDto<List> systemMsgDto) {
        String businessUrl = businessServerUrl + "/business-server/v1/query/message";

		JSONObject body = new JSONObject();

		JSONArray jsonArray = new JSONArray();

		JSONObject emailBody = new JSONObject();
		emailBody.put("mailContent",systemMsgDto.getContent());
		emailBody.put("attachmentAdd",systemMsgDto.getAttachmentAdd());
		emailBody.put("subject",systemMsgDto.getTitle());
		emailBody.put("receiveAddress", Joiner.on(",").join(systemMsgDto.getTargets()));
		emailBody.put("templateId",systemMsgDto.getTemplateId());
		jsonArray.add(emailBody);
		body.put("body",jsonArray);

		String bodyStr = body.toJSONString();
		log.info("发送邮件的地址："+businessUrl+"---请求体："+body);

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("agentId",systemMsgDto.getSenderId());
        httpHeaders.add("sessionId",systemMsgDto.getSessionId());
		httpHeaders.add("tenantId",systemMsgDto.getTenantId());
		httpHeaders.add("protype","Ews");
		httpHeaders.add("Content-Type","application/json;charset=utf-8");
        log.info("发送邮件的header"+httpHeaders);
        HttpEntity<String> httpEntity = new HttpEntity<>(bodyStr, httpHeaders);
        try {
            String result = restTemplate.postForObject(businessUrl, httpEntity, String.class);
            JSONObject jsonResult = JSON.parseObject(result);
            String code = jsonResult.getString("code");
            log.info("发送邮件的返回结果："+code);
            return code;
        } catch (RestClientException e) {
            log.info("邮件发送异常:"+e);
            return null;
        }
    }

    /**
     * @Author: Donny_dong
     * @Description: 获取主题信息
     * @Param:
     * @return:
     * @Date: 2020/11/25
     */
	@Override
	public DbResponse getMajorColor(String tenantId) {
		String eripUrl = eripAdapterUrl + "/csr/adapter/v1/query";
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("dataType","CfgParam");
		jsonBody.put("tenantId",tenantId);
		JSONArray filter = new JSONArray();
		JSONObject jsonParam = new JSONObject();
		jsonParam.put("name","category");
		jsonParam.put("type",0);
		jsonParam.put("value","THEME");
		filter.add(jsonParam);
		jsonBody.put("filter",filter);
		jsonBody.put("tenantId",tenantId);
		String bodyStr = jsonBody.toJSONString();
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.add("Content-Type","application/json");
		HttpEntity<String> httpEntity = new HttpEntity<>(bodyStr, httpHeaders);
		String result = null;
		try {
			result = restTemplate.postForObject(eripUrl, httpEntity, String.class);
		} catch (RestClientException e) {
			log.error("获取工作台主题色异常"+e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,ResponseConstant.SELECT_FAIL_MSG);
		}
		JSONObject jsonResult = JSON.parseObject(result);
		JSONObject info = jsonResult.getJSONObject("info");
		JSONArray dataArray = info.getJSONArray("data");
		return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,ResponseConstant.SELECT_SUCCESS_MSG,dataArray);
	}

	/**
	 * @Author: Donny_dong
	 * @Description: 浙能推送工单信息
	 * @Param:
	 * @return:
	 * @Date: 2020/11/25
	 */
	@Override
	public JSONObject pushWorkOrderInfo(JSONObject jsonObject) {
		String eripUrl = eripAdapterUrl + "/ticket/adapter/v1/query";
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.add("Content-Type","application/json");
		httpHeaders.add("erip-target","15600VOICE");
		httpHeaders.add("erip-source","ticket");
		httpHeaders.add("erip-action","query");
		httpHeaders.add("Cookie",null);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(jsonObject);
		HttpEntity<String> httpEntity = new HttpEntity<>(jsonArray.toJSONString(),httpHeaders);
		log.info("浙能推送工单信息至ERIP的浙能CRM系统adapter参数为:"+httpEntity);
		String response = restTemplate.postForObject(eripUrl, httpEntity, String.class);
		log.info("浙能推送工单信息至ERIP的浙能CRM系统adapter响应为:"+response);
		String replace = response.substring(1, response.length() - 1).replace("\\", "");
		JSONObject object = JSON.parseObject(replace);
		log.info("解析返回结果："+object);
		return object;
	}
}
